<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

        <title><?php echo $title;?></title>
        <?php $this->load->view('head');?>
        <script type="text/javascript" src="<?php echo CRUD_ROUTE; ?>js/head_scripts.js"></script>
        
        <script type="text/javascript">
            var fechaini = "";
            var fechafin = "";
            $(document).ready(function () {
                var b = new Date();
                var e = b.getDate();
                var a = b.getMonth();
                var f = b.getFullYear();
                var c = $("#full_calendar_home").fullCalendar({
                    buttonText: { today: '<?php echo lang('hoy');?>'},
                    disableDragging: true,
                    dayNames: ['<?php echo lang('domingo');?>', '<?php echo lang('lunes');?>', '<?php echo lang('martes');?>', '<?php echo lang('miercoles');?>',
                        '<?php echo lang('jueves');?>', '<?php echo lang('viernes');?>', '<?php echo lang('sabado');?>', '<?php echo lang('domingo');?>'],
                    dayNamesShort: ['<?php echo lang('dom');?>', '<?php echo lang('lun');?>', '<?php echo lang('mar');?>', '<?php echo lang('mie');?>',
                        '<?php echo lang('jue');?>', '<?php echo lang('vie');?>', '<?php echo lang('sab');?>', '<?php echo lang('dom');?>'],
                    monthNames: ["<?php echo lang('enero');?>", "<?php echo lang('febrero');?>", "<?php echo lang('marzo');?>", "<?php echo lang('abril');?>",
                        "<?php echo lang('mayo');?>", "<?php echo lang('junio');?>", "<?php echo lang('julio');?>", "<?php echo lang('agosto');?>",
                        "<?php echo lang('septiembre');?>", "<?php echo lang('octubre');?>", "<?php echo lang('noviembre');?>", "<?php echo lang('diciembre');?>"],
                    monthNamesShort: ["<?php echo lang('ene');?>", "<?php echo lang('feb');?>", "<?php echo lang('mar');?>", "<?php echo lang('abr');?>",
                        "<?php echo lang('may');?>", "<?php echo lang('jun');?>", "<?php echo lang('jul');?>", "<?php echo lang('ago');?>",
                        "<?php echo lang('sep');?>", "<?php echo lang('oct');?>", "<?php echo lang('nov');?>", "<?php echo lang('dic');?>"],                  
                    selectable: true,
                    selectHelper: true,
                    firstDay: 1,
                    lazyFetching: false,
                    select: function (i, d, g) {
                        fechaini = (i.getDate() < 10 ? "0"+i.getDate() : i.getDate())+"/"+
                                   ((i.getMonth()+1) < 10 ? "0"+(i.getMonth()+1) : (i.getMonth()+1))+"/"+
                                   i.getFullYear();
                        fechafin = (d.getDate() < 10 ? "0"+d.getDate() : d.getDate())+"/"+
                                   ((d.getMonth()+1) < 10 ? "0"+(d.getMonth()+1) : (d.getMonth()+1))+"/"+
                                   d.getFullYear();
                        //c.fullCalendar("unselect")
                    },
                    eventClick: function(calEvent, jsEvent, view) {
                        if(calEvent.reserva_cierre == 'C'){
                            if(confirm('<?php echo lang('confirm_stop_sales');?>')){
                                $.ajax({
                                    type: "POST",
                                    url: '<?php echo site_url("crud/operaciones/eliminar_cierre");?>',
                                    data: {'evento' : calEvent.id},
                                    success: function(datos){
                                        window.location.reload();
                                    }
                                });
                            }
                        }else{
                            if(confirm('<?php echo lang('confirm_aceptar_reserva');?>: '+calEvent.title+"?")){
                                $.ajax({
                                    type: "POST",
                                    url: '<?php echo site_url("crud/operaciones/confirmar_reserva");?>',
                                    data: {'evento' : calEvent.id},
                                    success: function(datos){
                                        window.location.reload();
                                    }
                                });
                            }
                        }
                    },
                    editable: false,
                    events: <?php echo json_encode($info_reservas);?>,
                    tarifas: '<?php echo json_encode($info_tarifas);?>'
                })

                
                var custom_buttons = '<td style="padding-left:10px">'+
                                         '<div class="ui-state-default ui-corner-left ui-corner-right">'+
                                            '<a href="#fallr-cierre"><img src="<?php echo site_url("public/crud/images/woo/lock_32.png"); ?>"/>'+'<?php echo lang('cerrar_ventas');?>'+'</a>'+
                                                '<img src="<?php echo site_url("public/crud/images/separador.png"); ?>"/>'+
                                            '<a href="#fallr-tarifa"><img src="<?php echo site_url("public/crud/images/woo/coins.png"); ?>"/>'+'<?php echo lang('cambiar_tarifa');?>'+'</a>'+
                                                '<img src="<?php echo site_url("public/crud/images/separador.png"); ?>"/>'+
                                            //'<a href="#"><img src="<?php echo site_url("public/crud/images/woo/Check.png"); ?>"/>'+'<?php echo lang('confirmar_reserva');?>'+'</a>'+
                                            //    '<img src="<?php echo site_url("public/crud/images/separador.png"); ?>"/>'+
                                            '<a href="#" id="select_all_link"><img src="<?php echo site_url("public/crud/images/woo/table_select_all.png"); ?>"/>'+'<?php echo lang('seleccionar_mes');?>'+'</a>'+
                                        '</div>'+
                                     '</td>';
                $('.fc-header-right').before(custom_buttons);
                
                var methods = {
                    tarifa : function(){
                        var cambiar_tarifa = function(){
                            var fecini = $(this).children('form').children('input[id="fechaini"]').val();
                            var fecfin = $(this).children('form').children('input[id="fechafin"]').val();
                            var tarifa = $(this).children('form').children('input[id="tarifa"]').val();
                            if(fecini.length < 1 || fecfin.length < 1 || tarifa.length < 1){
                                alert('<?php echo lang('mensaje_obligatorio_todos_campos');?>');
                            } else {
                                $.ajax({
                                    type: "POST",
                                    url: '<?php echo site_url("crud/operaciones/cambiar_tarifa");?>',
                                    data: {'fecini' : fecini, 'fecfin' : fecfin, 'tarifa' : tarifa},
                                    success: function(datos){
                                        $.fallr('hide');
                                        window.location.reload();
                                        //$("#full_calendar_home").fullCalendar('refetchEvents');
                                    }
                                });                                
                            }
                        }
                        
                        $.fallr('show', {
                            icon        : 'secure',
                            width       : '320px',
                            content     : '<h4>'+'<?php echo lang('cambiar_tarifa');?>'+'</h4>'
                                        + '<form>'
                                        +     '<input value="'+fechaini+'" id="fechaini" type="text"/'+'>'
                                        +     '<input value="'+fechafin+'" id="fechafin" type="text"/'+'>'
                                        +     '<input placeholder="'+'<?php echo lang('nueva_tarifa');?>'+'" id="tarifa" type="text"/'+'>'
                                        + '</form>',
                            buttons : {
                                button1 : {text: 'Submit', onclick: cambiar_tarifa},
                                button4 : {text: 'Cancel'}
                            },
                            zIndex  : 90 
                        },
                        function(){
                            //$("#fechaini").datepicker( $.datepicker.regional[ "es" ] );
                            //$("#fechafin").datepicker( $.datepicker.regional[ "es" ] );
                            $( "#fechaini" ).datepicker({
                                showAnim: 'slide',
                                dateFormat: 'dd/mm/yy'
                            });
                            $( "#fechafin" ).datepicker({
                                showAnim: 'slide',
                                dateFormat: 'dd/mm/yy'
                            });
                        });
                    },
                    cierre : function(){
                        var cerrar_ventas = function(){
                            var fecini = $(this).children('form').children('input[id="fechaini"]').val();
                            var fecfin = $(this).children('form').children('input[id="fechafin"]').val();
                            if(fecini.length < 1 || fecfin.length < 1){
                                alert('<?php echo lang('mensaje_obligatorio_todos_campos');?>');
                            } else {
                                $.ajax({
                                    type: "POST",
                                    url: '<?php echo site_url("crud/operaciones/cerrar_ventas");?>',
                                    data: {'fecini' : fecini, 'fecfin' : fecfin},
                                    success: function(datos){
                                        $.fallr('hide');
                                        window.location.reload();
                                    }
                                });                                
                            }
                        }
                        
                        $.fallr('show', {
                            icon        : 'secure',
                            width       : '320px',
                            content     : '<h4>'+'<?php echo lang('confirm_cerrar_ventas');?>'+'</h4>'
                                        + '<form>'
                                        +     '<input value="'+fechaini+'" id="fechaini" type="text"/'+'>'
                                        +     '<input value="'+fechafin+'" id="fechafin" type="text"/'+'>'
                                        + '</form>',
                            buttons : {
                                button1 : {text: 'Submit', onclick: cerrar_ventas},
                                button4 : {text: 'Cancel'}
                            },
                            zIndex  : 90 
                        },
                        function(){
                            //$("#fechaini").datepicker( $.datepicker.regional[ "es" ] );
                            //$("#fechafin").datepicker( $.datepicker.regional[ "es" ] );
                            $( "#fechaini" ).datepicker({
                                showAnim: 'slide',
                                dateFormat: 'dd/mm/yy'
                            });
                            $( "#fechafin" ).datepicker({
                                showAnim: 'slide',
                                dateFormat: 'dd/mm/yy'
                            });
                        });
                    }
                };
                $('#select_all_link').click(function(){
                    var d = $('#full_calendar_home').fullCalendar('getDate');
                    $("#full_calendar_home").fullCalendar('select', new Date(d.getFullYear(), d.getMonth(), 1), new Date(d.getFullYear(), d.getMonth(), dias(d.getMonth(), d.getFullYear())), true );
                });
                //button trigger
                $('a[href^="#fallr-"]').click(function(){
                    var id = $(this).attr('href').substring(7);
                    methods[id].apply(this,[this]);
                    return false;
                });

            });
            
           function dias(mes, anno) {
              mes = parseInt(mes);
                  anno = parseInt(anno);
              switch (mes) {
                    case 1 : case 3 : case 5 : case 7 : case 8 : case 10 : case 12 : return 31;
                        case 2 : return (anno % 4 == 0) ? 29 : 28;
                  }
                  return 30;
           }

        </script>
        
    </head>
    <body>
        <div id="layout">
            <?php echo $this->load->view('logo');?>
            <div id="top">
                <?php echo $this->load->view('menu');?>
                <div class="clear"></div>
                <?php echo $this->load->view('botonera_wizard'); ?>
            </div><!-- End of #top -->
            <div id="container" class="container_12">
                <!-- ======= .grid_12 - block begin ======= -->
                <div class="grid_12">
                    <?php if(isset($message)) if ($message != '') echo '<div class="alert info_msg">' . $message . '</div>'; ?>
                    <div class="box">
                        <div class="title"><span class="icon16_sprite i_calendar"></span><?php echo lang('crear_nuevo_producto'); ?></div>
                        <div class="inside">
                            <div id='full_calendar_home'></div>
                        </div>
                    </div>
                </div>
                <!-- ======= .grid_12 - block end ======= -->
            </div><!-- End of #container -->
        </div><!-- End of #layout -->
        <div class="clear"></div>
        <?php $this->load->view('foot');?>
    </body>
</html>